package com.isoft.controller.flightUpdate;

import com.isoft.bean.ResponseData;
import com.isoft.controller.BaseController;
import com.isoft.entity.ball.Blls;
import com.isoft.entity.flightUpdate.FlightUpdateVo;
import com.isoft.service.flightUpdate.FlightUpdateInfoService;
import com.isoft.service.flightUpdate.impl.FlightUpdateInfoServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author LiuGaoMing
 * @version 1.0
 * @description:
 * @date 2024/6/30 17:00
 */
@RestController
@RequestMapping("/flightUpdate")
@CrossOrigin
public class FlightUpdateInfoController extends BaseController {
    @Autowired
    private FlightUpdateInfoServiceImpl flightUpdateInfoService;

    //    获取所有
    @GetMapping("/all")
    public ResponseData<List<FlightUpdateVo>> selectPagedFlightUpdateInfo(
            @RequestParam(defaultValue = "1") int currentPage,
            @RequestParam(defaultValue = "10") int pageSize) {
        return flightUpdateInfoService.getFlightUpdateInfoWithTotal(currentPage, pageSize);
    }
//    通过metaid精确查询
    @GetMapping("/find/{META_ID}")
    public ResponseData<Object> getFlightUpdateInfoByMETAID(@PathVariable Integer META_ID) {
        if (META_ID == null) {
            return returnObject(null, "400", "航班号不能为空");
        }
        List<FlightUpdateVo> info = flightUpdateInfoService.getFlightUpdateInfoByMETAID(META_ID);
        if (info.isEmpty()){
            return returnObject(null, "400", "航班号不存在");
        }
        return returnObject(info);
    }
//    更新
    @PutMapping("/update")
    public ResponseData<Boolean> updateFlightUpdateInfoByMETAID(@RequestBody FlightUpdateVo flightUpdateVo) {
//     flightUpdateInfoService.updateFlightUpdateInfoByMETAID(flightUpdateVo);
        return flightUpdateInfoService.updateFlightUpdateInfoByMETAID(flightUpdateVo) ? returnBoolean(true) : returnBoolean(false);
    }
}